package com.quasar.hpatient.view.adapter;

import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.quasar.hpatient.R;
import com.quasar.hpatient.model.medicalmodel.PrescriptionDayData;

/**
 * author : 许建宏
 * Date: 2017/12/23 0023
 * View:
 */

public class HistoryPrescriptionAdapter  extends BaseQuickAdapter<PrescriptionDayData.ListBean.PerscriptDetailListBean, BaseViewHolder> {


    public HistoryPrescriptionAdapter() {
        super(R.layout.activity_historyprescription);
    }

    Boolean isShow = true;
    @Override
    protected void convert(BaseViewHolder helper, PrescriptionDayData.ListBean.PerscriptDetailListBean item) {


        final LinearLayout ll_isshow = helper.getView(R.id.prescription_ll_isshow);

        final LinearLayout ll_yincang=helper.getView(R.id.ll_yincang);
        ll_isshow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isShow) {
                    ll_yincang.setVisibility(View.VISIBLE);
                    isShow = false;
                } else {
                    ll_yincang.setVisibility(View.GONE);
                    isShow = true;
                }
            }
        });


        //医院
        if(item.getName()!=null){
            helper.setText(R.id.prescription_tv_hospital,item.getName());
        }

        //医生
        if(item.getRName()!=null && item.getRName().length()>0){
            helper.setText(R.id.prescription_tv_doctorname,item.getRName());
        }else{
            helper.setText(R.id.prescription_tv_doctorname,"本人");
        }

        //时间
        if(item.getPeriodBegin()!=null){
            helper.setText(R.id.prescription_tv_time,item.getPeriodBegin().substring(0,item.getPeriodBegin().length()-9));
        }

        //药品信息
        StringBuffer stringBuffer=new StringBuffer();
        if(item.getMName()!=null){
            stringBuffer.append(item.getMName());
        }
        if(item.getDoseName()!=null){
            stringBuffer.append(item.getDoseName());
        }

        helper.setText(R.id.prescription_tv_title,stringBuffer.toString());

        //药品信息
        StringBuffer stringBuffer1 = new StringBuffer();
        if (item.getPrescriptionDoseDetail() != null) {
            if (item.getPrescriptionDoseDetail().size() > 0) {
                stringBuffer1.append("每天服用" + item.getPrescriptionDoseDetail().size() + "次" + "\n");
            }
        }
        if (item.getPrescriptionDoseDetail() != null) {
            for (int i = 0; i < item.getPrescriptionDoseDetail().size(); i++) {
                stringBuffer1.append("第" + item.getPrescriptionDoseDetail().get(i).getDetailId() + "次"
                        + item.getPrescriptionDoseDetail().get(i).getUseTime().substring(10, 16) +
                        "服用" + "\t" + item.getPrescriptionDoseDetail().get(i).getUseCount() +"*"+ item.getDoseName() + "\n");
            }
            helper.setText(R.id.prescription_tv_desc, stringBuffer1.toString());
        }

    }

}
